<?php
class ome_ctl_admin_neworder extends desktop_controller{



    public function updateOrderItem()
    {
        $this->page('admin/order/updateOrderItem.html');
    }

    /*
     * 保存
     */
    public function doUpdateOrder()
    {
        $this->begin('');
        $order_bns = trim($_POST['order_bns']);
        $price = $_POST['price'];
        $bnArr = explode(',', $order_bns);
        //防止最后的逗号
        $orderBnArr = array();
        foreach ($bnArr as $key => $val) {
            if (!empty($val)) {
                $orderBnArr[] = trim($val);
            }
        }
        $res= kernel::single('ome_order_edit')->updateItemObj($orderBnArr);
        $this->end(true, '修改成功');
    }
    //修改已支付金额
    public function updatepayed()
    {

        $this->page('admin/order/updateOrderpayed.html');

    }
    /*
     * 保存
     */
    public function doupdatepayed()
    {
        $this->begin('');
        $order_bns = trim($_POST['order_bns']);
        $price = $_POST['price'];
        $bnArr = explode(',', $order_bns);
        $oOrders = app::get('ome')->model('orders');
        #记录操作日志
        $oOperation_log = app::get('ome')->model('operation_log');
        //防止最后的逗号
        $orderBnArr = array();
        foreach ($bnArr as $key => $val) 
        {
            if (!empty($val)) 
            {
                $order = $oOrders->dump ( array ('order_bn' => trim($val) ),'payed,order_id' );
                $oOrders ->update(array('payed'=>$price),array('order_id' => $order['order_id']));   
                $oOperation_log->write_log('order_edit@ome', $order['order_id'],"订单支付金额由".$order['payed']."修改为".$price);                 
                
            }
        }
        $this->end(true, '修改成功');
    }
    public function updatedivide()
    {
        $this->begin('');
        $order_ids=$_POST['order_id'];
        foreach ($order_ids as $key => $value) 
        {
            kernel::single("ome_order_fail")->modifyOrderDividefee($value);
        }
        $this->end(true, app::get('base')->_('分摊实付金额'));
    }
    //重算分摊实付金额
    public function Batchupdatedivide()
    {
        $this->page('admin/order/batchupdatedivide.html');
    }
    public function doBatchupdatedivide()
    {
        $this->begin('');
        $order_bns = trim($_POST['order_bns']);
        $bnArr = explode(',', $order_bns);
        $oOrders = app::get('ome')->model('orders');
        //防止最后的逗号
        $orderBnArr = array();
        foreach ($bnArr as $key => $val) 
        {
            if (!empty($val)) 
            {
                $order = $oOrders->dump ( array ('order_bn' => trim($val) ),'payed,order_id' );
                kernel::single("ome_order_fail")->modifyOrderDividefee($order['order_id']);
            }
        }
        $this->end(true, '修改成功');
    }
}